#!/bin/bash

set -e

echo "job=<%= spec.job.name %> index=<%= spec.index %> id=<%= spec.id %>"

# Stdout and stderr
echo -ne "<%= properties.errand1.stdout * properties.errand1.stdout_multiplier %>"

<% if properties.errand1.run_package_file %>
./packages/errand1/file.sh
<% end %>

echo -ne "<%= properties.errand1.stderr * properties.errand1.stderr_multiplier %>" 1>&2

# Log files
mkdir -p sys/log/errand1
echo -n "<%= properties.errand1.logs.stdout %>" > sys/log/errand1/stdout.log
echo -n "<%= properties.errand1.logs.custom %>" > sys/log/custom.log

# Delay
<% if p('errand1.blocking_errand') %>
until [ -a "jobs/errand1/unblock_errand" ]; do
  sleep 0.5
done
<% end %>

sleep 1

# Exit code
exit <%= properties.errand1.exit_code %>
